package pl.edu.agh.pros.android.ros;

import org.ros.namespace.GraphName;
import org.ros.node.AbstractNodeMain;
import org.ros.node.ConnectedNode;
import org.ros.node.topic.Publisher;

public class SensorPublisher extends AbstractNodeMain {

	private Publisher<std_msgs.String> publisher;
	private String previousSpeed;

	@Override
	public GraphName getDefaultNodeName() {
		return new GraphName("pros_camera/sensor_publisher");
	}

	@Override
	public void onStart(final ConnectedNode connectedNode) {
		publisher = connectedNode.newPublisher("/koala/sensors", std_msgs.String._TYPE);
	}

	public void publish(String speed) {
		if (publisher != null && !speed.equals(previousSpeed)) {
			std_msgs.String str = publisher.newMessage();
			str.setData(speed);
			publisher.publish(str);
			previousSpeed = speed;
		}
	}

}
